# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.shortcuts import render, redirect
from django.http import HttpResponse
# Create your views here.
from django.contrib.auth import authenticate,login,logout
def login_ask(request):
    if request.method=='POST':
        user=request.POST.get('name')
        psw=request.POST.get('password')
        res=authenticate(username=user,password=psw)
        if res:
            login(request,res)
            request.session.set_expiry(60*60*2)
            return redirect('/question/')
        else:
            a={'error':'用户名或密码错误'}
            return render(request,'signin.html',context=a)
    else:
        return render(request,'signin.html')
def logout_view(request):
    logout(request)
    return redirect('/auth/')